package assetloanapi

import (
	"encoding/json"

	ledgerapi "github.com/hyperledger/fabric-samples/asset-kx/chaincode-go/chaincode/ledger-api"
)

const DataType = "ASSET-LOAN"

type AssetLoan struct {
	AssetNo    string `json:"assetNo"`
	LoanNo     string `json:"loanNo"`
	LoanAmount string `json:"loanAmount"`
	DocType    string `json:"docType"`
}


func (b *AssetLoan) Keys() []string {
	return []string{b.AssetNo , b.LoanNo}
}
func (b *AssetLoan) Serialize() ([]byte, error) {
	return json.Marshal(b)
}
func (b *AssetLoan) DataType() string{
	return DataType
}

func UnmarshalStateData(content []byte) (ledgerapi.StateData, error) {
	return Unmarshal(content)
}

func Unmarshal(content []byte) (*AssetLoan, error) {
	if len(content) == 0 {
		return nil, nil
	}
	al := &AssetLoan{}
	if err := json.Unmarshal(content, al); err != nil {
		return nil, err
	}
	return al, nil
}